package adv.i31.RobotMin3d;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.ToggleButton;

public class MainActivity extends Activity
{
	private final Teachbox	teachbox		= new Teachbox();
	private final float		MAX_CAM_X		= 6f;
	private float			camDirection	= -.01f;
	private long			lastTimeMillis	= System.currentTimeMillis();
	private TextView		textView1;
	private TextView		textView2;
	private TextView		textView3;
	private TextView		textView4;
	private TextView		textView5;
	private TextView		textView6;
	private TextView	textView7;
	

	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		// min3d stuff
		setContentView(R.layout.activity_main);

		LinearLayout ll = (LinearLayout) this.findViewById(R.id.scene1Holder);
		//ll.addView(_glSurfaceView);

		textView1 = (TextView) findViewById(R.id.textView1);
		textView2 = (TextView) findViewById(R.id.textView2);
		textView3 = (TextView) findViewById(R.id.textView3);
		textView4 = (TextView) findViewById(R.id.textView4);
		textView5 = (TextView) findViewById(R.id.textView5);
		textView6 = (TextView) findViewById(R.id.textView6);
		textView7 = (TextView) findViewById(R.id.textView7);
		
		btnActive = (ToggleButton) findViewById(R.id.btnActive);

		mRobotConnection = new Rvm1Connection();

		teachbox.init(this,mRobotConnection);
		
		mBluetoothStuff = new BluetoothUi();
		mBluetoothStuff.init(this);
		

		mBluetoothStuff.addCallback(new BluetoothUi.Callback()
		{	
			@Override
			public void onConnect(BluetoothConnection con)
			{
				// TODO Auto-generated method stub
				mRobotConnection.setConnection(con);
				
				runOnUiThread(new Runnable()
				{
					@Override
					public void run()
					{
						btnActive.setBackgroundColor(Color.GREEN);
					}
				});
				

				
				int i=10;
				while(--i>0) {
					Log.i("gwwg","sending HELLO");
					con.sendString("HELLO\r\n");
					try {
						Thread.sleep(1000);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				
			}

			@Override
			public void onDisconnect()
			{
				// TODO Auto-generated method stub
				mRobotConnection.setConnection(null);
				
				runOnUiThread(new Runnable()
				{
					@Override
					public void run()
					{
						btnActive.setBackgroundColor(Color.RED);
					}
				});
			}
		});
		
	}

	double rawx,rawy;
	private BluetoothUi	mBluetoothStuff;
	private Rvm1Connection	mRobotConnection;
	private ToggleButton	btnActive;
	
}